package org.learnaholic.application.ui.swing;

import org.learnaholic.application.model.Knowledge;
import org.learnaholic.application.model.MemoryItem;
import org.learnaholic.application.model.TestResultEvent;
import org.learnaholic.application.model.TestResultListener;
import org.learnaholic.application.ui.CellColorFactory;
import org.learnaholic.ui.itemtable.TableCell;


public class ItemCell extends TableCell
{
	private final String id;
	
	public ItemCell(final MemoryItem item)
	{
		super(item.getListItem().getKeyValue());
		
		item.getTestResultLog().addTestResultListener(new TestResultListener()
		{

			public void logChanged(TestResultEvent evt)
			{
				setColours(item.getKnowlegde());
			}
			
		});
		
		setColours(item.getKnowlegde());

		setSelected(false);
		
		id = item.getListItem().getId();
		
	}
	
	private void setColours(Knowledge knowledge)
	{
		super.setSelectedBackground(CellColorFactory.getSelectedBackground(knowledge));
		super.setSelectedForeground(CellColorFactory.getSelectedForeground(knowledge));
		super.setNonSelectedBackground(CellColorFactory.getUnselectedBackground(knowledge));
		super.setNonSelectedForeground(CellColorFactory.getUnselectedForeground(knowledge));
	}
	

	/**
	 * @return
	 */
	public String getId()
	{
		return id;
	}
}
